import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true

  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }

    ]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/general/index',
    name: 'Example',
    meta: { title: '系统配置', icon: 'el-icon-s-tools' },
    children: [
      {
        path: 'general',
        name: 'General',
        component: () => import('@/views/general/index'),
        meta: {
          title: '通用配置', icon: 'el-icon-s-help'
        }
      },
      {
        path: 'ERP',
        name: 'ERP',
        component: () => import('@/views/ERP/index'),
        meta: { title: 'ERP设置', icon: 'el-icon-s-order' }
      },
      {
        path: 'BOM',
        name: 'BOM',
        component: () => import('@/views/BOM/index'),
        meta: { title: 'BOM配置', icon: 'el-icon-s-operation' }
      },
      {
        path: 'mapping',
        name: 'Mapping',
        component: () => import('@/views/mapping/index'),
        meta: {
          title: '物料属性映射', icon: 'el-icon-s-data'
        }
      },
      {
        path: 'classify',
        name: 'Classify',
        component: () => import('@/views/classify/index'),
        meta: { title: '物料分类属性映射', icon: 'el-icon-menu' }
      },
      {
        path: 'encode',
        name: 'Encode',
        component: () => import('@/views/encode/index'),
        meta: { title: '编码规则', icon: 'el-icon-info' }
      },
      {
        path: 'NumEncode',
        name: 'NumEncode',
        component: () => import('@/views/NumEncode/index'),
        meta: { title: '图号编码规则', icon: 'el-icon-picture' }
      },
      {
        path: 'info',
        name: 'Info',
        component: () => import('@/views/info/index'),
        meta: { title: '消息通知', icon: 'el-icon-message-solid' }
      },
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/user/index'),
        meta: { title: '用户管理', icon: 'el-icon-user-solid' }
      },

    ]
  },

  {
    path: '/data',
    component: Layout,
    redirect: '/goods/index',
    name: 'Form',
    meta: { title: '基础数据处理', icon: 'form' },
    children: [
      {
        path: 'goods',
        name: 'Goods',
        component: () => import('@/views/goods/index'),
        meta: { title: ' 物品分类', icon: 'el-icon-s-goods' }
      },
      {
        path: 'generation',
        name: 'Generation',
        component: () => import('@/views/generation/index'),
        meta: { title: '代别', icon: 'el-icon-s-ticket' }
      },
      {
        path: 'version',
        name: 'Version',
        component: () => import('@/views/version/index'),
        meta: { title: '版本', icon: 'el-icon-s-operation' }
      },
      {
        path: 'stratification',
        name: 'Stratification',
        component: () => import('@/views/stratification/index'),
        meta: { title: '层别', icon: 'el-icon-more' }
      },
      {
        path: 'unit',
        name: 'Unit',
        component: () => import('@/views/unit/index'),
        meta: { title: '单位', icon: 'el-icon-s-open' }
      },
      {
        path: 'color',
        name: 'Color',
        component: () => import('@/views/color/index'),
        meta: { title: '颜色', icon: 'el-icon-s-shop' }
      },
      {
        path: 'surface',
        name: 'Surface',
        component: () => import('@/views/surface/index'),
        meta: { title: '表面处理', icon: 'el-icon-s-opportunity' }
      },
      {
        path: 'inventory',
        name: 'Inventory',
        component: () => import('@/views/inventory/index'),
        meta: { title: '库存单位', icon: 'el-icon-s-home' }
      },
      {
        path: 'procurement',
        name: 'Procurement',
        component: () => import('@/views/procurement/index'),
        meta: { title: '采购单位', icon: 'el-icon-s-claim' }
      },
      {
        path: 'supply',
        name: 'Supply',
        component: () => import('@/views/supply/index'),
        meta: { title: '补给方式', icon: 'el-icon-s-promotion' }
      },
      {
        path: 'receipt',
        name: 'Receipt',
        component: () => import('@/views/receipt/index'),
        meta: { title: '收货方式', icon: 'el-icon-s-flag' }
      },
      {
        path: 'morphology',
        name: 'Morphology',
        component: () => import('@/views/morphology/index'),
        meta: { title: '形态属性', icon: 'el-icon-s-check' }
      },
      {
        path: 'cleaning',
        name: 'Cleaning',
        component: () => import('@/views/cleaning/index'),
        meta: { title: '清洗等级', icon: 'el-icon-s-finance' }
      },
    ]
  },

  {
    path: '/permissions',
    component: Layout,
    redirect: '/assignment/index',
    name: 'Permissions',
    meta: { title: '权限设置', icon: 'el-icon-s-platform' },
    children: [
      {
        path: 'assignment',
        name: 'Assignment',
        component: () => import('@/views/assignment/index'),
        meta: { title: '权限分配', icon: 'el-icon-finished' }
      },
      {
        path: 'system',
        name: 'System',
        component: () => import('@/views/system/index'),
        meta: { title: '系统管理', icon: 'el-icon-c-scale-to-original' }
      },
      {
        path: 'pagemanagement',
        name: 'PageManagement',
        component: () => import('@/views/PageManagement/index'),
        meta: { title: '页面管理', icon: 'el-icon-files' }
      },
      {
        path: 'PageMenu',
        name: 'PageMenu',
        component: () => import('@/views/PageMenu/index'),
        meta: { title: '菜单管理', icon: 'el-icon-notebook-1' }
      },

    ]
  },



  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
